<?php

function spAjaxLoad( $id, $func )
{
	return new spDiv(array(
		"id"	=> $id,
		"class" => "ajax-".$func
	));
}

class spAjax extends spDiv
{
	private $id;
	private $param;
	
	public function __construct( $param )
	{
		parent::__construct();
	
		$this->param = $param;
	
		if ( isset($param["create_id"]) )
		{
			$this->id = $param["create_id"];
			parent::setId( $this->id );
		}
	}
	
	public function render()
	{
		parent::render();	
		
		if ( isset($this->param["callfunc"]) )
		{
			$data = http_build_query( $this->param["data"]);
			?>
				<script type="text/javascript">

					jQuery(document).ready(function(){

						sel = jQuery("#<?php echo $this->id; ?>");
						callfunc = "<?php echo $this->param["callfunc"]?>";
						data = "<?php echo $data; ?>";
					
						sel.append(
							"<img src='"+spHome+"/wp-content/plugins/sigmaphp/images/ajax-loader.gif' alt=''/>"
						);
				
						sel.load( spHome+"/wp-admin/admin-ajax.php?action=sp_ajax_response&formType=loadonly&loadonly="+callfunc, data, function(response, status, xhr){
							spInit();
						});
					});
					
				</script>
			<?php
		}			
	}
}

?>